package com.xcc.wchatrobot;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.RadioButton;

public class MainActivity extends AppCompatActivity implements CompoundButton.OnCheckedChangeListener {
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        RadioButton radio1 = findViewById(R.id.radio1);
        RadioButton radio2 = findViewById(R.id.radio2);
        RadioButton radio3 = findViewById(R.id.radio3);

        int level = IdControl.getInstance().getLevel();
        switch (level) {
            case 0:
                radio1.setChecked(true);
                break;
            case 1:
                radio2.setChecked(true);
                break;
            default:
            case 2:
                radio3.setChecked(true);
                break;
        }
        radio1.setOnCheckedChangeListener(this);
        radio2.setOnCheckedChangeListener(this);
        radio3.setOnCheckedChangeListener(this);
    }

    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        if (isChecked) {
            switch (buttonView.getId()) {
                case R.id.radio1:
                    IdControl.getInstance().setLevel(0);
                    break;
                case R.id.radio2:
                    IdControl.getInstance().setLevel(1);
                    break;
                case R.id.radio3:
                    IdControl.getInstance().setLevel(2);
                    break;
            }
        }
    }
}
